﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Algorithms
{
    public class KdTreeNode<T>
    {
        // Value of node.
        private T value;
        private bool verticalLine = true;
        // Pair of child nodes.
        private KdTreeNode<T> leftChild;
        private KdTreeNode<T> rightChild;

        /**
        * the rectangle corresponding to a node.
        */
        private RectHV rectangle = null;

        /// <summary>
        /// Initializes a new instance of the <see cref="Node{T}"/> class.
        /// </summary>
        /// <param name="value">The value of the node.</param>
        public KdTreeNode(T value)
        {
            this.value = value;
        }

        public KdTreeNode<T> getLeft()
        {
            return this.leftChild;
        }

        public void setLeft(KdTreeNode<T> left)
        {
            this.leftChild = left;
        }

        public KdTreeNode<T> getRight()
        {
            return this.rightChild;
        }

        public void setRight(KdTreeNode<T> right)
        {
            this.rightChild = right;
        }

        public T getValue()
        {
            return this.value;
        }

        /**
         * get rectangle.
         * 
         * @return RectHV
         */
        public RectHV getRectangle()
        {
            return this.rectangle;
        }

        /**
         * set rectangle.
         * 
         * @param rect
         *            rectangle
         */
        public void setRectangle(RectHV rect)
        {
            this.rectangle = rect;
        }

        /// <summary>
        /// Gets the value of the node.
        /// </summary>
        /// <value>The value of the node.</value>
        public T Value
        {
            get { return this.value; }
            internal set { this.value = value; }
        }

        /// <summary>
        /// Gets the left child node of the current node.
        /// </summary>
        /// <value>The left child node.</value>
        public KdTreeNode<T> LeftChild
        {
            get { return this.leftChild; }
            internal set { this.leftChild = value; }
        }

        /// <summary>
        /// Gets the right child node of the current node.
        /// </summary>
        /// <value>The right child node.</value>
        public KdTreeNode<T> RightChild
        {
            get { return this.rightChild; }
            internal set { this.rightChild = value; }
        }

        public bool isVerticalLine()
        {
            return this.verticalLine;
        }

        public void setVerticalLine(bool vectical)
        {
            this.verticalLine = vectical;
        }

        /// <inheritdoc/>
        public override string ToString()
        {
            return string.Format("{0}({1})",
                this.value,
                this.verticalLine ? "|" : "-"
                );
        }

    }
}
